# -*- coding: utf-8 -*-
# @Time : 2021/9/17 15:50
# @Author : jiangping
# @Email : jp@gmail.com
# @File : MRYX_SPFL_004.py
# @Project : mryx_test
"""验证搜索功能"""

from time import sleep
from appium.webdriver.common.mobileby import MobileBy as By
from appium import webdriver
desired_capabilities = {
    'platformName':'Android',
    'deviceName':'127.0.0.1:62001',
    'platformVersion':'7.1.2',
    'appPackage':'cn.missfresh.application',
    'appActivity':'cn.missfresh.module.main.view.SplashActivity',
    'noReset':True
}
driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_capabilities)
sleep(2)
#定位器
#首页
goods_sort_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().text("分类")')#首页分类
milk_sort_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().text("乳品烘焙")')#首页分类
search_locator = (By.ID,'cn.missfresh.application:id/search_layout')#分类页搜索输入框
search_input_locator = (By.XPATH,'//android.widget.EditText[@resource-id=\"cn.missfresh.application:id/search_view\"]')#搜索页搜素输入框
search_btn_locatot = (By.ANDROID_UIAUTOMATOR,'new UiSelector().text("搜索")')#搜索按钮
# 1、点击分类
goods_sort_element = driver.find_element(*goods_sort_locator).click()
sleep(2)
# 2、点击分类页搜索输入框
driver.find_element(*search_locator).click()
sleep(2)
# 3、输入零食
driver.find_element(*search_input_locator).send_keys("零食")
sleep(2)
# 4、点击【搜索】
driver.find_element(*search_btn_locatot).click()


sleep(5)
driver.quit()